﻿@{
    ViewBag.Title = ViewBag.siteName + " - Danh sách sản phẩm yêu thích";
    ViewBag.Description = ViewBag.htmlDescription;
    ViewBag.Keywords = ViewBag.htmlKeywords;
}

@model PagedList.IPagedList<BDShop.Entities.WishList>
@using BDShop.Utilities.Managers;
@using BDShop.Configuration;
@using BDShop.Framework.Extensions;
@using PagedList.Mvc;
@using BDShop.Entities;
@using BDShop.Business.Cache;
@using BDShop.Framework.Security;
<!--Left Part-->
@Html.Partial("Partial/_LeftAccMenu", null)
<!--Left End-->

<!--Middle Part Start-->
<div id="content">
    <!--Breadcrumb Part Start-->
    <div class="breadcrumb"><a href="/">Trang chủ</a> » <a href="/thong-tin-tai-khoan.html">Tài khoản</a> » <a>Danh sách yêu thích</a></div>
    <!--Breadcrumb Part End-->
    <h1>Danh sách yêu thích</h1>
    <form enctype="multipart/form-data" method="post" action="#">
        <div class="cart-info">
            <table>
                <thead>
                    <tr>
                        <td class="image">Hình ảnh</td>
                        <td class="name">Tên sản phẩm</td>
                        <td class="price">Giá</td>
                        <td></td>
                    </tr>
                </thead>
                <tbody>

                    @foreach (var wl in Model)
                    {
                        ProductCacheComplex product = ProductCache.Instance.Get().Where(p => p.ID == wl.ProductID).FirstOrDefault();

                        string[] categoryDefinition = null;
                        if (!string.IsNullOrEmpty(product.CategoryDefinition))
                        {
                            categoryDefinition = product.CategoryDefinition.Split('|')[0].Split('#');
                        }
                        var url = UrlManager.ProductDetailUrl(product.ID, product.Name, categoryDefinition);

                        string ID = SercurityHelper.ConvertStringToHex(SercurityHelper.Encrypt(wl.ID.ToString(), true));
                        <tr>
                            <td class="image"><a href="@url">
                                <img style="width: 45px" class="lazy" data-original="@Path.Combine(BDShopConfiguration.Storage.MainImagePath, product.MainImage)" src="@Path.Combine(BDShopConfiguration.Storage.MainImagePath, product.MainImage)" alt="@product.Name" /></a></td>
                            <td class="name"><a href="@url">@product.Name</a></td>
                            <td class="price">@product.Price.ToCurrencyString(false, true)</td>
                            <td class="quantity">
                                <img title="Hủy" alt="Hủy" src="/Images/remove.png" onclick="RemoveProductOfWishList('@ID');"></td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div>
            <!--Pagination Part Start-->
            @if (Model.PageCount > 1)
            {
                <div class="paging">
                    <div class="links">
                        @Html.PagedListPager(Model, page => Url.Action("WishList", new { page }))
                    </div>
                    <div class="results">
                        Trang @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) của @Model.PageCount
                    </div>
                </div>
            }
            <!--Pagination Part End-->
        </div>
    </form>
</div>
<!--Middle Part End-->
<div class="clear"></div>
<script>
    function RemoveProductOfWishList(wlID) {
        var r = confirm("Quý khách chắc chắn hủy sản phẩm này!");
        if (r == false) {
            return;
        }
        
        $.post("/Account/RemoveProductOfWishList", { ID: wlID })
               .done(function (json) {
                   json = json || {};
                   if (json.success) {
                       location.reload();
                   } else if (json.errors) {
                       alert("Có lỗi trong quá trình hủy sản phẩm trong danh sách yêu thích.");
                   }
               })
               .error(function () {
                   alert("Có lỗi trong quá trình hủy sản phẩm trong danh sách yêu thích.");
               });
    };

</script>
